﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using BusinessLayer.Model.Services;
using BusinessLayer.Model.Services.Abstract;

namespace BusinessLayer.Model.Entities
{
    /// <summary>
    /// Entidad que representa una noticia.
    /// </summary>
    public class News
    {
        /// <summary>
        /// Id de la noticia
        /// </summary>
        public Guid NewsID { get; internal set; }
        
        /// <summary>
        /// Titulo de la noticia
        /// </summary>
        public string Title { get; set; }
 
        /// <summary>
        /// Contenido de la noticia
        /// </summary>
        public string Content { get; set; } 

        /// <summary>
        /// Descripcion de la noticia
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Fecha de la noticia
        /// </summary>
        public DateTime Date { get; set; }


        
        /// <summary>
        /// Constructor
        /// </summary>
        public News()
        {
            this.NewsID = Guid.NewGuid();
            this.Title = String.Empty;
            this.Description = String.Empty;
            this.Date = DateTime.Now;
            this.Content = String.Empty;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="content"></param>
        public News(string title, string description, string content)
        {
            this.NewsID = Guid.NewGuid();
            this.Title = title;
            this.Description = description;
            this.Date = DateTime.Now;
            this.Content = content;
        }

        ///// <summary>
        ///// Salva el contenido de la noticia en su archivo respectivo
        ///// </summary>
        ///// <param name="content">Contenido a salvar</param>
        //internal void SaveNewsContentFile(string content)
        //{
        //    ApplicationService appService = new ApplicationService();

        //    string path = appService.NewsFilesFolder + NewsID.ToString() + ".txt";
            
        //    if (File.Exists(path))
        //        File.Delete(path);

        //    StreamWriter sw = new StreamWriter(path);
        //    sw.Write(content);
            
        //    sw.Close();

        //    this.PathToContent = path;
        //}

        ///// <summary>
        ///// Carga el contenido de la noticia
        ///// </summary>
        ///// <param name="path">Path al archivo de contenido</param>
        ///// <returns>Contenido de la noticia</returns>
        //internal static string LoadContent(string path)
        //{
        //    return File.ReadAllText(path);
        //}

    }
}
